'use strict';

const Controller = require('egg').Controller;

class EditCartListController extends Controller {
    async index() {
    
        const { ctx } = this;
        console.log(ctx.request.body);
        var res;
        var {id,productNum,checked} = ctx.request.body;
        if(checked !== undefined && productNum !==undefined){
            res = await ctx.model.User.updateOne({"cartList._id":id},{$set:{
                "cartList.$.productNum":productNum,
                "cartList.$.checked":checked,
            }});
        }else if(checked !== undefined && productNum ==undefined){
            res = await ctx.model.User.updateOne({"cartList._id":id},{$set:{
                "cartList.$.checked":checked,
            }});
        }else if(checked == undefined && productNum !==undefined){
            res = await ctx.model.User.updateOne({"cartList._id":id},{$set:{
                "cartList.$.productNum":productNum,
            }});
        }
        console.log(res);
        ctx.body ={
            msg:"修改相关数据成功",
            code:200,
        }
    }
}

module.exports = EditCartListController;
